package de.hsb.ai.devil.ui;

import jade.core.AID;
import jade.domain.FIPAAgentManagement.DFAgentDescription;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;

import de.hsb.ai.devil.agent.DevilManagementAgent;
import de.hsb.ai.devil.agent.DevilManagementAgent.EventHandler;

public class DevilManagerGUI extends JFrame implements EventHandler {
	
	private AID playerA, playerB;
	
	private JButton button;
	
	private DevilManagementAgent agent;

	public DevilManagerGUI(final DevilManagementAgent agent) {
		this.agent = agent;
		
		button = new JButton("Start");
		button.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				agent.startGame(playerA, playerB);
			}
			
		});
		
		button.setEnabled(false);
		add(button);
		
		pack();
		setVisible(true);
	}

	@Override
	public void handle(DFAgentDescription agent, Event e) {
		if (agent.getName().getLocalName().equals("player1")) {
			playerA = agent.getName();
		}
		
		if (agent.getName().getLocalName().equals("player2")) {
			playerB = agent.getName();
		}
		
		button.setEnabled(playerA != null && playerB != null);
	}
}
